package com.example.file;

import com.example.Service.FileService;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Button button = (Button) this.findViewById(R.id.button);
		button.setOnClickListener(new ButtonClickListener());
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	private final class ButtonClickListener implements View.OnClickListener{

		@Override
		public void onClick(View v) {
			EditText filenameText = (EditText) findViewById(R.id.filename);
			EditText filecontentText = (EditText) findViewById(R.id.filecontent);
			String filename = filenameText.getText().toString();
			String filecontent = filecontentText.getText().toString();
			FileService service = new FileService(getApplicationContext());
			try {
				service.save(filename,filecontent);
				Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();

			} catch (Exception e) {
				Toast.makeText(getApplicationContext(), R.string.fail, Toast.LENGTH_LONG).show();
				e.printStackTrace();
			}
					
		}
		
	}

}
